package com.simple.common.entity.dto.pay.india;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.simple.common.entity.ReqContext;
import com.simple.common.entity.po.sys.ChannelComp;
import com.simple.common.entity.po.sys.Product;
import com.simple.common.entity.po.sys.Trade;
import lombok.Data;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
 * @author Mr.kang
 * @date 2021年01月21日 11:54
 * @description
 */
@Data
public class IndiaWithdrawalDto extends IndiaBaseDto {

    /**
     * 提供静态方法方便创建
     *
     * @param trade
     * @param context
     * @param channel
     * @param product
     * @return
     */
    public static IndiaWithdrawalDto generateDto(Trade trade,
                                                 ReqContext context,
                                                 ChannelComp channel,
                                                 Product product) {
        IndiaWithdrawalDto indiaWithdrawalDto = new IndiaWithdrawalDto();
        indiaWithdrawalDto.setTrade(trade);
        indiaWithdrawalDto.setContext(context);
        String extraInfo = trade.getExtraInfo();
        Map map = Mono.fromCallable(()->new ObjectMapper().readValue(extraInfo, Map.class)).block();
        indiaWithdrawalDto.setExtra(map);
        indiaWithdrawalDto.setChannel(channel);
        indiaWithdrawalDto.setProduct(product);
        return indiaWithdrawalDto;
    }

}
